<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自动跳转</title>
    <style>
        p{
            text-align:center;
        }
        span{
            color:red;
        }

    </style>
</head>
<body>
<p>
    <span id="time">5</span>s后自动跳转
</p>
<script>

    var second = 5;
    var id;
    function fun(){
        second--;

        if(second<=0)
        {
            clearInterval(id);
            //当秒等于0时结束计时
            location.href = "https://www.bilibili.com";
        }
        var time = document.getElementById("time");
        //获取对象
        time.innerHTML = second+"";


    }

    id = setInterval(fun,1000);

</script>
</body>
</html>